using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SkillBase : MonoBehaviour
{
    public float coolDown;
    protected Player player;
    protected float coolDownTimer;
    protected virtual void UnLock()
    {

    }
    protected virtual void Start()
    {
        player = PlayerManager.Instance.player;
        UnLock();
    }
    public virtual bool CanUseSkill()
    {
        if(coolDownTimer<0)
        {
            UseSkill();
            coolDownTimer = coolDown;
            return true;
        }
        return false;
    }
    protected virtual void UseSkill()
    {

    }
    protected virtual void Update()
    {
        coolDownTimer -= Time.deltaTime;
    }
    protected virtual Transform FindClosestEnemy(Transform checkTransform,float radius)
    {
        Collider2D[] colliderArray = Physics2D.OverlapCircleAll(checkTransform.position, radius);
        Transform rangeEnemy = null;
        float distance = float.MaxValue;
        foreach (var hit in colliderArray)
        {
            if (hit.GetComponent<Enemy>() != null)
            {
                float distanceToEnemy = Vector2.Distance(checkTransform.position, hit.gameObject.transform.position);
                if (distance > distanceToEnemy)
                {
                    distance = distanceToEnemy;
                    rangeEnemy = hit.gameObject.transform;
                }
            }
        }
        return rangeEnemy;
    }
}
